package com.qk.management.service.impl;

import com.qk.common.PageResult;
import com.qk.entity.Course;
import com.qk.management.mapper.CourseMapper;
import com.qk.management.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author ZLJ
 * @date 2025/10/9 10:54
 * @Description
 */
@Service
@SuppressWarnings("all")
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public void deleteById(Integer id) {
        courseMapper.deleteById(id);
    }

    @Override
    public void getBySubject(Integer subject) {
        courseMapper.getBySubject(subject);
    }

    @Override
    public List<Course> selectAll() {
        return courseMapper.selectAll();
    }

    @Override
    public void update(Course course) {
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.update(course);
    }

    @Override
    public void addCourse(Course course) {
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.insert(course);
    }

    @Override
    public Course getById(Integer id) {
        Course course=courseMapper.getById(id);
        return course;
    }

    @Override
    public PageResult<Course> page(String name, Integer subject, String target, Integer page, Integer pageSize) {
        Integer total = courseMapper.count(name,subject,target);
        Integer offset = (page-1)*pageSize;
        List<Course> rows = courseMapper.selectByPage(name,subject,target,offset,pageSize);
        return PageResult.<Course>builder().total(total).rows(rows).build();
    }
}
